package com.swind.fast.modules.app.halali.partner.service.impl;

import com.swind.fast.common.util.oConvertUtils;

import com.swind.fast.modules.app.halali.partner.entity.RestaurantMealDealItem;
// import com.swind.fast.modules.app.halali.partner.entity.RestaurantMealDealItemBill;
import com.swind.fast.modules.app.halali.partner.mapper.RestaurantMealDealItemMapper;
import com.swind.fast.modules.app.halali.partner.service.IRestaurantMealDealItemService;
// import com.swind.fast.modules.app.halali.partner.model.SpaceAnnouncementModel;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.ApplicationContext;

import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.date.DateBetween;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;

import javax.annotation.Resource;

import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import com.swind.fast.modules.app.halali.partner.vo.request.DealVo;
import com.swind.fast.modules.app.halali.partner.vo.request.DealItemVo;

/**
 * @Description: 项目
 * @Author: swind
 * @Date:   2021-11-20
 * @Version: V1.0
 */
@Slf4j
@Service
public class RestaurantMealDealItemServiceImpl extends ServiceImpl<RestaurantMealDealItemMapper, RestaurantMealDealItem> implements IRestaurantMealDealItemService {

    public void saveOrUpdateDealItems(String restaurntId, DealVo dealVo) {
        String dealId = dealVo.getId();
        List<DealItemVo> items = dealVo.getItems();
        this.baseMapper.removeDealItems(restaurntId, dealId);

        List<RestaurantMealDealItem> saveItems = new ArrayList<RestaurantMealDealItem>();
        for (DealItemVo item : items) {
            RestaurantMealDealItem dealItem = oConvertUtils.entityToModel(item, RestaurantMealDealItem.class);
            dealItem.setRestaurantId(restaurntId);
            dealItem.setDealId(dealId);
            saveItems.add(dealItem);
        }
        if (oConvertUtils.listIsNotEmpty(saveItems)) {
            this.saveBatch(saveItems);
        }
    }

}
